//
//  AYuVisitorViewController.swift
//  SHWeibo3
//
//  Created by 余伟康 on 16/7/19.
//  Copyright © 2016年 wangce. All rights reserved.
//
//  访客视图控制器->逻辑

import UIKit

class AYuVisitorViewController: UIViewController {

    // 判断用户是否登录
    var isLogin: Bool = AYuUserAccountViewModel.sharedTools.isLogin
    
    // 访客视图view
    var visitorView :AYuVisitorView?  // 访客视图view
    
    override func loadView() {
        isLogin ? (view = tableView) : setupVisitorView()
    }
    
    // 设置访客视图
    func setupVisitorView(){
    
        visitorView = AYuVisitorView()
        visitorView?.closure = {
            print("登陆或者按钮点击")
            self.loginClick()
        }
        
        view = visitorView
        setupNav()
    }
    
    // 设置导航栏按钮
    func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        
    }
    
     // MARK: - 监听按钮
    @objc private func loginClick(){
        print("按钮被点击了")
        // 加载授权界面
        let oauthVc = AYuOAuthViewController()
        presentViewController(UINavigationController(rootViewController: oauthVc), animated: true, completion: nil)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    func setupUI(){
    }
    
    // MARK: - 懒加载控件
    lazy var tableView : UITableView = UITableView()
}
